﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SilverlightInEnterprise.SharedCode.Repository.Models;
using SilverlightInEnterprise.SharedCode.Repository.Cache;

namespace SilverlightInEnterprise.SharedCode.MVC.Controllers
{
    public class ProductController : Controller
    {
        


        public ActionResult Index()
        {
            if (ProductCache.Cache== null)
            {
                using (SlinEnterpriseContext c = new SlinEnterpriseContext())
                {

                    ProductCache cache = new ProductCache(c.Products.ToArray());
                }
            }
            return View(ProductCache.Cache.Items);
        }
        public ActionResult Create()
        {
            return View(new Product());
        }
        [HttpPost]
        public ActionResult Save(Product product)
        {
            if (product.Id == 0)
            {
                // do create 
                ProductCache.Cache.Insert(product);
            }
            else
            {
                //do update
            }
            return View();
        }
    }
}
